|
|
 |
|
 |
|
|
Performance Considerations |
|
|
|
 |
|
 |
|
|
One of the most frequent reasons for deviating from the guidelines just given is to improve performance. If obtaining a total sales figure for a given salesperson requires summing several thousand records, for example, you might find it worthwhile to include a Total Sales field in the salesperson table that is updated each time a sale is made. This way, when reports are generated, the application doesn't have to do large numbers of calculations, and the report process is dramatically faster. However, your program must ensure that the Total Sales field is consistently and accurately updated. |
|
|
|
 |
|
 |
|
|
Another reason to deviate from the guidelines is to avoid opening a large number of tables at the same time. Because each open table uses precious resources and takes up memory, having too many open tables can slow down your application. |
|
|
|
 |
|
 |
|
|
Deviating from the guidelines results in two major consequences. The first is increasing the size of the database because of redundant data. The second is the possibility of having incorrect data in some of the records because a piece of data was changed and not all the affected records were updated. |
|
|
|
 |
|
 |
|
|
There are trade-offs between application performance and data storage efficiency. For each design, you must look at the trade-offs and decide on the optimum design. |
|
|
|
|
|
|
|
|
When information is entered into a table, records usually are stored in the order in which they are added. This order is the physical order or natural order of the data. However, you usually want to view or process data in an order different from the order of entry; that is, you want to define a logical order. You also frequently need to find a specific record in a table. Doing so by scanning the table in its physical order can be quite time-consuming. |
|
|
|
|
|
|
|
|
An index provides a method of showing a table in a specific order. An index is a special table that contains a key value (usually derived from the values of one or more fields) for each record in the data table; the index itself is stored in a specific logical order. The index also contains pointers that tell the database engine where the actual record is located. This type of index is similar to the index in the back of this book. By using the book's index, you easily can look up key words or topics, because it contains pointers (page numbers) to tell you where to find the information. |
|
|
|
|
|
|
|
|
The structure of an index allows for rapid data search and retrieval. If you have a table of names indexed alphabetically, you rapidly can retrieve the record for a specific name by searching the index. To get an idea of the value of such an index, imagine a phone book that lists the customer names in the order in which they signed up for phone service. If you live in a large city, finding a person's number could take forever, because you have to look at each line until you find the one you want. |
|
|
|
|
|
|
|
|
A table can have a number of different indexes associated with it to provide different organizations of the data. For example, an employee table can have indexes on last name, date of birth, date of hire, and pay scale. Each index shows the same data in a different order, for a different purpose. |
|
|
|
|
|